package com.txx.controller;

import com.txx.service.FileService;
import com.txx.vo.ImageVO;
import com.txx.vor.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Author: zgc
 * @Date: 2021/5/21 10:35
 */

@RestController
@CrossOrigin
@RequestMapping("/file")
public class FileController {
    @Autowired
    private FileService fileService;

    @PostMapping("/upload")
    public SysResult upload(MultipartFile file) throws IOException {

        ImageVO imageVO = fileService.upload(file);
        if(imageVO == null){
            return SysResult.fail();
        }
        return SysResult.success(imageVO);
    }

    //实现文件的删除功能
    //URL: /file/deleteFile
    @DeleteMapping("/deleteFile")
    public SysResult fileRemove(String virtualPath){

        fileService.fileRemove(virtualPath);
        return SysResult.success();
    }

}
